<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>短信发送量统计分析</title>
<link href="../../layui/css/layui.css" rel="stylesheet" type="text/css">
<link href="../../css/style.css" rel="stylesheet" type="text/css">
<script src="../../layui/layui.js"></script>
<script src="../../js/jquery-1.8.3.js"></script>
<script src="../../js/util.js"></script>
<script>
        layui.use(['laypage', 'layer', 'table', 'form', 'jquery', 'laydate', 'element'], function () {
            var table = layui.table;
            var laypage = layui.laypage;
            var layer = layui.layer;
            var form = layui.form;
            var $ = layui.$;
            var laydate = layui.laydate;
            //var index = layer.load(1); 
            var tableData = {
                elem: '#table',
                id: "modelReload", //id
                url: '/smsReportTotal/find?countWay=city',
                method: 'post',
                request: {
                    pageName: 'page',
                    limitName: 'limit'
                },
                response: {
                    statusName: 'code',
                    statusCode: 0,
                    msgName: 'msg',
                    countName: 'count',
                    dataName: 'data'
                }
                , limit: 10,
                limits: [10, 20, 30, 40, 50],
                layout: ['prev', 'page', 'next'],
                prev: "上一页",
                next: "下一页",
                page: true //开启分页
                , cols: [[
                    {
                        field: 'cityName', title: '地市', rowspan: 2
                    }
                    , {title: '长短信', colspan: 3, align: 'center'}
                    , {title: '正常短信', sort: true, colspan: 2, align: 'center'}
                    , {title: '费用统计', sort: true, colspan: 2, align: 'center'} 
                    , {title: '外地市用户', colspan: 2, align: 'center'}
                    , {title: '外省用户', colspan: 2, align: 'center'}], [
                      {field: 'longNum', title: '发送量'}
                    , {field: 'longNumSplit', title: '长短信拆分后数量'}
                    , {field: 'longPercent', title: '占比'}
                    , {field: 'normalNum', title: '发送量'}
                    , {field: 'normalPercent', title: '占比'}
                    , {field: 'totalCount', title: '总发送量'}
                    , {field: 'totalFee', title: '总费用(总发送量*0.03元/条)'}
                    , {field: 'otherCities', title: '发送量'}//,event: 'setSign', style: 'cursor: pointer;'}
                    , {field: 'otherCitiesPercent', title: '占比'}
                    , {field: 'otherProvinces', title: '发送量'}//,event: 'setSign', style: 'cursor: pointer;'}
                    , {field: 'otherProvincesPercent', title: '占比'}
                ]]
                
                ,done:function (res) {   //返回数据执行回调函数
   					layer.closeAll('loading'); //关闭loading 
				}
            	
            };
            
            
            $('#query').on('click', function () {
                //身份识别
                $.ajax({
                    type: 'post',
                    async: false,
                    url: '/util/findUser',
                    success: function (json) {
						
                        if (json.duty == 2 || json.duty == 3) {
                            layer.msg("对不起，您的权限不足，请选择其他的统计方式")
                        } else {
                            var startTime = $("#startTime").val();
                            var endTime = $("#endTime").val();
                            var way = $("input[name='way']:checked").val();
                            var cityId = $("#cityId").val(); 
                            
                            if (judetmentDate(startTime, endTime) && way == 1) {
                                layer.msg("您选择的时间超出了30天，请重新选择");
                            } else {
                                 var index = layer.load(1, {
                                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                                }); 
                                 layer.load(); //上传loading 
							if (json.duty == 0) {
								table.reload('modelReload', {
									method : 'post',
									loading : true, //翻页加loading
									page : {
										curr : 1
									},
									where : {
										way : way,
										startTime : formatDate(startTime),
										endTime : formatDate(endTime),
										month : $("#yearmonth").val(),
										year : $("#year").val(),
										cityId : cityId
									}
								});
							}else{
								table.reload('modelReload2', {
									method : 'post',
									loading : true, //翻页加loading
									page : {
										curr : 1
									},
									where : {
										way : way,
										startTime : formatDate(startTime),
										endTime : formatDate(endTime),
										month : $("#yearmonth").val(),
										year : $("#year").val(),
										cityId : cityId
									}
								});
							}
							}
                        }
                    }, error: function () {
                        layer.msg('系统异常，请联系管理员处理!');
                    }
                });

            });

            //身份识别
            $(document).ready(function () {
                $.ajax({
                    type: 'post',
                    async: false,
                    url: '/util/findUser',
                    success: function (json) {
                   		if (json.duty == 1) {
                    		$("#cityId").val(json.cityId);
                            $("#cityId").attr("disabled", true);
                            form.render();
					}

					if (json.duty != 0) {
						tableData = {
							elem : '#table',
							id : "modelReload2", //id
							url : '/smsReportTotal/find?countWay=city',
							method : 'post',
							request : {
								pageName : 'page',
								limitName : 'limit'
							},
							response : {
								statusName : 'code',
								statusCode : 0,
								msgName : 'msg',
								countName : 'count',
								dataName : 'data'
							},
							limit : 10,
							limits : [ 10, 20, 30, 40, 50 ],
							layout : [ 'prev', 'page', 'next' ],
							prev : "上一页",
							next : "下一页",
							page : true, //开启分页
							cols : [ [
								{
									field : 'cityName',
									title : '地市',
									rowspan : 2,
									align : 'center'
								}
								, {
									title : '长短信',
									colspan : 3,
									align : 'center'
								}
								, {
									title : '正常短信',
									sort : true,
									colspan : 2,
									align : 'center'
								}
								, {
									field : 'totalCount',
									title : '总发送量',
									rowspan : 2,
									align : 'center'
								}
								, {
									title : '外地市用户',
									colspan : 2,
									align : 'center'
								}
								, {
									title : '外省用户',
									colspan : 2,
									align : 'center'
								} ], [
								{
									field : 'longNum',
									title : '发送量',
									align : 'center'
								}
								, {
									field : 'longNumSplit',
									title : '长短信拆分后数量',
									align : 'center'
								}
								, {
									field : 'longPercent',
									title : '占比',
									align : 'center'
								}
								, {
									field : 'normalNum',
									title : '发送量',
									align : 'center'
								}
								, {
									field : 'normalPercent',
									title : '占比',
									align : 'center'
								}
								, {
									field : 'otherCities',
									title : '发送量',
									align : 'center'
								} //,event: 'setSign', style: 'cursor: pointer;'}
								, {
									field : 'otherCitiesPercent',
									title : '占比',
									align : 'center'
								}
								, {
									field : 'otherProvinces',
									title : '发送量',
									align : 'center'
								} //,event: 'setSign', style: 'cursor: pointer;'}
								, {
									field : 'otherProvincesPercent',
									title : '占比',
									align : 'center'
								}
							] ],                
							done : function(res) { //返回数据执行回调函数
								layer.closeAll('loading'); //关闭loading 
							}
						};
					}
				}, error: function () {
                        layer.msg('系统异常，请联系管理员处理!');
                    }
                });
            });
            //导出
            $('#download').on('click', function () {
                //身份识别
                $.ajax({
                    type: 'post',
                    async: false,
                    url: '/util/findUser',
                    success: function (json) {
                        var startTime = $("#startTime").val();
                        var endTime = $("#endTime").val();
                        var way = $("input[name='way']:checked").val();
                        var cityId = $("#cityId").val();
                        if (judetmentDate(startTime, endTime) && way == 1) {
                            layer.msg("您选择的时间超出了30天，请重新选择");
                        } else {
                            var url = "/smsReportTotal/download?countWay=city"
                                + "&way=" + way
                                + "&startTime=" + formatDate(startTime)
                                + "&endTime=" + formatDate(endTime)
                                + "&month=" + $("#yearmonth").val()
                                + "&cityId=" + cityId
                                + "&year=" + $("#year").val();
                            location.href = url;
                        }
                    }
                });
            });
            //时间下拉框设置
            //时间选择器的样式
            //获取系统时间，做时间选择
            //获取指定月的天数
            var myDate = new Date();
           
            //获取当前的年份
            var year = myDate.getFullYear();
            //获取当前月的月份

            var month = myDate.getMonth() + 1;
/*             //上一月的年份
            var inityear = (month - 1 > 0 ? year : year - 1);
            //上个月的月份
            var initmonth = (month - 1 > 0 ? month - 1 : 12); */
            
            //上一月的年份
            var inityear = year;
            //上个月的月份
            var initmonth = month;

            initmonth = (initmonth < 10 ? 0 + "" + initmonth : initmonth);

            //初始化最大月份
            var maxdate = inityear + '-' + initmonth + '-' + 25;

            //前6个月的月份
            var minmonth = month - 6;

            //前6个月的年份
            var minyear = (minmonth > 0 ? year : year - 1);

            minmonth = (minmonth > 0 ? minmonth : minmonth + 12);

            //初始化最小月份
            var mindate = minyear + '-' + minmonth + '-' + 01;

            var maxtime = inityear + '-' + initmonth + "-" + myDate.getDate();
            var mintime = minyear  + '-' + minmonth + "-01";
			
            var initiaSartTime = inityear + "-" + initmonth + "-" + '01';
            var initiaEndTime = inityear + "-" + initmonth + "-" + myDate.getDate();

            var init = inityear + "" + initmonth;
            
            laydate.render({
                elem: '#year'
                , type: 'year'
                , btns: ['clear', 'confirm']
                , trigger: 'click'
                , format: 'yyyy'
                , value: inityear
                , max: maxtime
                , min: mintime
            });
            laydate.render({
                elem: '#yearmonth'
                , type: 'month'
                , btns: ['clear', 'confirm']
                , trigger: 'click'
                , format: 'yyyyMM'
                , value: init
                , max: maxdate
                , min: mindate
            });
            laydate.render({
                elem: '#startTime'
                , type: 'date'
                , btns: ['clear', 'confirm']
                , trigger: 'click'
                , value: initiaSartTime
                , max: maxtime
                , min: mintime
            });
            laydate.render({
                elem: '#endTime'
                , type: 'date'
                , max: maxtime
                , trigger: 'click'
                , btns: ['clear', 'confirm']
                , value: initiaEndTime
                , max: maxtime
                , min: mintime
            });
            table.render(tableData);

            table.on('tool(demoEvent)', function (obj) {
                var data = obj.data;
                if (obj.event === 'setSign') {
                    layer.open({
                        type: 2,
                        title: '外地人口发送统计',
                        shadeClose: true,
                        shade: false,
                        area: ['800px', '500px']
                        , content: ['fieldCount.html?cityId=' + data.cityId
                        + "&way=" + $("input[name='way']:checked").val()
                        + "&month=" + $("#yearmonth").val()
                        + "&startTime=" + formatDate($("#startTime").val())
                        + "&endTime=" + formatDate($("#endTime").val()),
                            'no']
                    });
                }
            });
        });
    </script>
</head>
<body>
	<!--nav-->
	<div class="layui-html-limit">
		<!--container-->
		<div class="layui-content-body">
			<div class="scroll-box">
				<div class="breadcrumb-box">
					<span class="layui-breadcrumb" lay-separator="|"> <a
						href="javascript:returnIndex2()">首页&nbsp;</a> <a href="">&nbsp;报表管理&nbsp;</a>
						<a href="">&nbsp;短信发送量统计分析&nbsp;</a> <a href="">&nbsp;按地市统计分析&nbsp;</a>
					</span>
				</div>
				<div class="content-box ">
					<div class="form-select-box">
						<form class="layui-form layui-form-pane" action="">
							<div class="layui-form-item">

								<div class="layui-inline" pane="">
									<label class="layui-form-label">按统计方式</label>
									<div class="layui-input-block">
										<a href="/view/reportManage/countByCity.html" id="city">
										<input type="radio" name="countWay" title="按地市" checked=""></a>
										<a href="/view/reportManage/countByCounty.html" id="county">
										<input type="radio" name="countWay" title="按区县"></a>
										<a href="/view/reportManage/countByType.html" id="type">
										<input type="radio" name="countWay" title="按类型"></a> 
										<a href="/view/reportManage/countByMgr.html" id="mgr">
										<input type="radio" name="countWay" title="按项目"></a> 
										<a href="/view/reportManage/countByContent.html" id="content">
										<input type="radio" name="countWay" title="按内容"></a> 
										<a href="/view/reportManage/countByRegion.html" id="region">
										<input type="radio" name="countWay" title="按区域"></a> 
										<a href="/view/reportManage/countByStation.html" id="station">
										<input type="radio" name="countWay" title="按基站"></a>
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<div class="layui-inline">
									<label class="layui-form-label">地市</label>
									<div class="layui-input-block">
										<select name="cityId" lay-filter="cityId" id="cityId">
											<option value="">请选择</option>
											<option value="11">苏州</option>
											<option value="12">淮安</option>
											<option value="13">宿迁</option>
											<option value="14">南京</option>
											<option value="15">连云港</option>
											<option value="16">徐州</option>
											<option value="17">常州</option>
											<option value="18">镇江</option>
											<option value="19">无锡</option>
											<option value="20">南通</option>
											<option value="21">泰州</option>
											<option value="22">盐城</option>
											<option value="23">扬州</option>
											<option value="25">省级</option>
										</select>
									</div>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">发送时间</label>
								<div class="layui-inline">
									<div class="layui-inline">
										<div class="layui-inline">
											<input type="radio" name="way" value="2" title="按年"
												checked="">
										</div>
										<div class="layui-inline">
											<input type="text" id="year" placeholder="请选择年份"
												class="layui-input" style="width: 100px;" readonly>
										</div>
									</div>
									<div class="layui-inline">
										<input type="radio" name="way" value="0" title="按月" checked="">
									</div>
									<div class="layui-inline">
										<input type="text" id="yearmonth" placeholder="请选择月份"
											class="layui-input" style="width: 100px;" readonly>
									</div>
									<div class="layui-form-item">
										<div class="layui-inline">
											<div class="layui-inline">
												<input type="radio" name="way" value="1" title="按时间段">
											</div>
											<div class="layui-inline">
												<div class="layui-input-inline" style="width: 130px;">
													<input type="text" name="date" id="startTime"
														autocomplete="off" class="layui-input" readonly>
												</div>
												<div class="layui-form-mid">-</div>
												<div class="layui-input-inline" style="width: 130px;">
													<input type="text" name="date" id="endTime"
														autocomplete="off" class="layui-input" readonly>
												</div>
											</div>
										</div>
										<div class="layui-inline">
											<button class="layui-btn layui-btn-normal" type="button"
												id="query">查询</button>
											<button class="layui-btn layui-btn-normal" type="button"
												id="download">导出</button>
										</div>
										<div style="color: red">短信汇总统计数据只保存6个月，查询时间段不可超出30天</div>
									</div>
								</div>
							</div>

						</form>
					</div>
					<!--表格-->
					<div class="table-box">
						<table class="layui-hide" id="table" lay-filter="demoEvent">
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>
</html>